package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallProductBanner;
import com.novax.ex.activity.infrastructure.mapper.MallProductBannerMapper;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * Description:轮播图片配置
 *
 * @author Deucalion@novax.email
 * @date 2023/2/21 17:21
 */
@Service
public class MallProductBannerService extends BaseService {
    @Resource
    private MallProductBannerMapper mallProductBannerMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallProductBannerMapper;
    }

    /**
     * @description: 获取列表图
     * @author: Wade
     * @date: 2/22/23 8:25 PM
     * @param: [mallProductId]
     * @return: java.util.List<java.lang.String>
     **/
    public List<String> getImgsByProductId(Long mallProductId){
        Map<String, Object> map = new HashMap<>();
        map.put("mallProductId", mallProductId);
        List<MallProductBanner> banners = mallProductBannerMapper.selectList(map);
        if (Objects.nonNull(banners)) {
            List<String> imgs = banners.stream().map(MallProductBanner::getImg).collect(Collectors.toList());
            return imgs;
        }
        return null;
    }
    /**
     * @description: 获取主图
     * @author: Wade
     * @date: 2/22/23 8:25 PM
     * @param: [mallProductId]
     * @return: java.lang.String
     **/
    public String getByMainImg(Long mallProductId){
        MallProductBanner banner = mallProductBannerMapper.getByMainImg(mallProductId);
        if(Objects.nonNull(banner)){
            return banner.getImg();
        }
        return "";
    }

    /** 统计商品图片数量 */
    public long countBannerNum(Long mallProductId){
        return mallProductBannerMapper.countBannerNum(mallProductId);
    }
}
